package com.vd.tbsms.parse;

import java.io.File;
import java.io.FileInputStream;
import java.util.Properties;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

public class PropParse {
	private Log log = LogFactory.getLog(PropParse.class);
	private static PropParse Ins = new PropParse();
	private PropParse(){
	}
	public static PropParse getInstance(){
		return Ins;
	}
	public void init() throws Exception{
		synchronized (Ins) {
			if(prop == null){
				prop = new Properties();
				File fl= new File("config.properties");
				if(fl.exists()){
					prop.load(new FileInputStream(fl));
				}else{
					log.warn("config not exit;; load default config");
					prop.load(Thread.currentThread().getClass().getResourceAsStream("config.properties"));
				}
				
			}
		}
	}
	public String getValue(String key){
		if(prop == null){
			try {
				init();
			} catch (Exception e) {
				log.error("init Exception", e);
				return null;
			}
		}
		return prop.getProperty(key);
	}
	private Properties prop;
	public Properties getProp() {
		if(prop == null){
			try {
				init();
			} catch (Exception e) {
				log.error("init Exception", e);
			}
		}
		return prop;
	}
}
